package pl.ydp.components.mathcell.mathrecognizer.geometry.extractor.features
{
	import flash.geom.Point;
	
	import pl.ydp.components.mathcell.mathrecognizer.engine.Parameters;
	import pl.ydp.components.mathcell.mathrecognizer.geometry.classification.PrimitiveType;
	
	public class ShapeFeatures
	{
		public function ShapeFeatures(primitives:Array)
		{
			loopTails = new Array;
			
			if (primitives.length == 0){
				return;
			}
			
			
			// find LOOP TRAILS
			
			var ref:Number;
			var test:Number;
			var loopFound:Boolean = false;
			
			for (ref = 0 ; ref < primitives.length ; ref ++){
				if (PrimitiveType.isLoop(primitives[ref].type)){
					
					for (test = 0 ; test < primitives.length ; test ++){
						
						if (PrimitiveType.isLine(primitives[test].type)){
							
							if ((Point.distance(primitives[test].begin, primitives[ref].begin) < Parameters.MAX_JOINT_DISTANCE)  ||  
								(Point.distance(primitives[test].begin, primitives[ref].end) < Parameters.MAX_JOINT_DISTANCE)  ||  
								(Point.distance(primitives[test].end, primitives[ref].begin) < Parameters.MAX_JOINT_DISTANCE)  ||  
								(Point.distance(primitives[test].end, primitives[ref].end) < Parameters.MAX_JOINT_DISTANCE)){
									
								loopTails.push(new LoopTrailData(ref, test) );
								
							}
							
						}
						
					}  //  end for (ref = 0
					
				}
				
			}  //  end for (test = 0
			
			
		}
		
		public var loopTails:Array;		
		

	}
}